from PyQt5.QtWidgets import QDialog, QVBoxLayout, QFrame, QHBoxLayout, QLabel, QTextEdit, QPushButton
from config import frame_config,Text_config,button_config,input_config
from func import view

class ShopComment(QDialog):
    def __init__(self, parent=None):
        super(ShopComment, self).__init__(parent)
        self.parent = parent
        self.client=self.parent.client
        self.shop_name=self.parent.shop_name
        self.shop_id=self.parent.shop_id
        title=f'{self.shop_name}的评论'
        self.setWindowTitle(title)
        self.resize(600, 600)
        main_layout = QVBoxLayout(self)
        frame=view.create_scroll(main_layout)
        frame.setStyleSheet(frame_config.frame_style2)
        self.mainLayout = QVBoxLayout(frame)
        self.initUI()

    def initUI(self):
        self.dic={
                    1 : '🤬🤬答辩玩意',
                    2 : '😠😠不愿多说',
                    3 : '😑😑马马虎虎',
                    4 : '😗😗还不错哟',
                    5 : '😍😍十分喜欢'
                }
        parser={
            'shop_id':self.shop_id,
        }
        data=self.client.get_comments(parser)
        if data.get('code')==200:
            self.show_comment(data.get('msg'))
        else:
            label=QLabel()
            label.setText(data.get('msg'))
            label.setStyleSheet(Text_config.text_style1)
            self.mainLayout.addWidget(label)
        exit_btn = QPushButton()
        exit_btn.setText('返回')
        exit_btn.setStyleSheet(button_config.button_style4)
        self.mainLayout.addWidget(exit_btn)
        exit_btn.clicked.connect(self.exit)

    def show_comment(self,data):
        for item in data:
            frame1=QFrame()
            frame1.setStyleSheet(frame_config.frame_style1)
            self.mainLayout.addWidget(frame1)
            frame1.setFixedHeight(60)
            text=f"{item['username']}({item['date']}):{self.dic[item['comment']]};{item['comments']}"
            ed_text=QTextEdit(frame1)
            ed_text.setText(text)
            ed_text.setStyleSheet(input_config.input_style7)
            ed_text.setReadOnly(True)
            ed_text.setFixedSize(570,60)


    def exit(self):
        self.close()
        self.accept()

    def accept(self):
        super().accept()





